package org.hubwork.base.common;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class HubBusinessImplMyBatis implements HubBusiness{
	
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor=Throwable.class)
	public void runTX() throws Exception {
		HubT1 ht1 = new HubT1();
		ht1.setId(5);
		ht1.setName("hub55");
		HubT2 ht2 = new HubT2();
		ht2.setId(6);
		ht2.setName("hub66");
		HubApplicationContext.get(HubT1DAOImplMyBatis.class).save(ht1);
		HubApplicationContext.get(HubT2DAOImplMyBatis.class).save(ht2);	
		List<HubT1> t1List = HubApplicationContext.get(HubT1DAOImplMyBatis.class).find();
		for(HubT1 t1: t1List){
			System.out.println(t1.getId() + "/" + t1.getName());
		}
		List<HubT2> t2List = HubApplicationContext.get(HubT2DAOImplMyBatis.class).find();
		for(HubT2 t2: t2List){
			System.out.println(t2.getId() + "/" + t2.getName());
		}
		throw new Exception();
	}
}
